<?php

use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
#use Illuminate\Support\Facades\Schema;

return new class extends Migration
{
    /**
     * Run the migrations.
     *
     * @return void
     */
    public function up()
    {
        if (Schema::hasTable('admin_logs')) return;
        Schema::create('admin_logs', function (Blueprint $table) {
            $table->increments('id')->comment('管理员操作日志表');
            $table->string('name')->default('')->comment('操作名称');
            $table->string('uri')->default('')->comment('请求链接');
            $table->string('desc')->default('')->comment('操作描述');
            $table->text('params')->comment('请求参数, 存json');
            $table->string('method')->default('')->comment('请求方式');
            $table->integer('res_code')->default(0)->comment('返回状态码');
            $table->string('res_msg')->default('')->comment('返回错误信息');
            $table->longText('res_content')->comment('返回信息');
            $table->unsignedInteger('admin_id')->default(0)->comment('操作人id');
            $table->string('ip_address')->default('')->comment('操作人ip');
            $table->bigInteger('start_time')->default(0)->comment('请求开始时间，存毫秒时间戳');
            $table->bigInteger('end_time')->default(0)->comment('请求结束时间，存毫秒时间戳');
            $table->integer('con_time')->default(0)->comment('请求消耗的时间，毫秒');
            $table->dateTime('created_at')->default(\DB::raw('CURRENT_TIMESTAMP'));
            $table->timestamp('updated_at')->default(\DB::raw('CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP'));
            $table->index('uri');
            $table->index('admin_id');
            $table->index('created_at');
        });
    }

    /**
     * Reverse the migrations.
     *
     * @return void
     */
    public function down()
    {
        if (!is_production()) {
            if (!is_production()) Schema::dropIfExists('admin_logs');
        }
    }
};
